<?php
if ($_SESSION['sid']!=1 && $_SESSION['sid']!=94) {
    exit('无权限查看！');
}

include '/var/www/html/new/d/common/func.inc.php';

$sql_merged = <<<SQL
SELECT l.id,l.title,l.apply_did,s.* FROM pft_terminal_share s
LEFT JOIN uu_land l ON l.salerid=s.preSalerID WHERE 1=1
SQL;

if ($_GET['land']) {
    $sql_merged .= " AND l.title like '%". safetxt($_GET['land']) ."%' ";
}

include_once '/var/www/html/new/d/module/common/Db.class.php';
$dbConf = include '/var/www/html/new/d/module/common/db.conf.php';// 远端服务器配置信息
\PFT\Db::Conf($dbConf['localhost']);
$db = \PFT\Db::Connect();

if ($_SERVER['REQUEST_METHOD']=='POST' && !empty($_POST['action'])) {
    if ($_POST['action']=='cancel_merged') {
        $sql = "DELETE FROM pft_terminal_share WHERE id=? LIMIT 1";
        if (\PFT\Db::execute($sql, array($_POST['id']))) {
            echo 1;
        } else {
            echo 0;
        }
        exit;
    }
} else {
    if ($_GET['action']=='get_merged' && is_numeric($_GET['salerid'])) {
        $sql_merged .= " AND s.nowSalerID={$_GET['salerid']} AND s.dstatus=0";
        $data = \PFT\Db::fetchAll($sql_merged);
        echo json_encode($data);
        exit;
    }
    else {
        $sql_merged .= " AND s.dstatus=1";
    }
    $data = \PFT\Db::fetchAll($sql_merged);


}
\PFT\Db::Close();

include 'common/header.html';
include 'common/left.html';
include 'tpl/terminal_share_list.html';
include 'common/footer.html';

?>